package jmine.tec.web.front.domain;

import java.io.InputStream;
import java.math.BigDecimal;

import jmine.tec.web.front.dispatcher.request.BackOfficeRequestStatusBuilder;

import org.apache.commons.io.IOUtils;

import bancosys.tec.persist.builders.AbstractDBBuilder;
import bancosys.tec.utils.date.Date;
import bancosys.tec.utils.date.Timestamp;

/**
 * @author lundberg
 */
public class BackOfficeRequestBuilder extends AbstractDBBuilder<BackOfficeRequest> {

    private final BackOfficeRequest request = this.createBean();

    public static BackOfficeRequestBuilder aRequest() {
        BackOfficeRequestBuilder builder = new BackOfficeRequestBuilder();
        builder.requestingUser("john.smith");
        builder.requestTimestamp(new Timestamp());
        builder.status(BackOfficeRequestStatusBuilder.aRequestStatus().build());
        builder.content(IOUtils.toInputStream("content"));
        builder.type(BackOfficeRequestTypeBuilder.aRequestType().build());
        return builder;
    }

    @Override
    protected BackOfficeRequest doBuild() {
        return this.request;
    }

    public BackOfficeRequestBuilder requestingUser(String value) {
        this.request.setRequestingUser(value);
        return this;
    }

    public BackOfficeRequestBuilder requestTimestamp(Timestamp value) {
        this.request.setRequestTimestamp(value);
        return this;
    }

    public BackOfficeRequestBuilder status(BackOfficeRequestStatus value) {
        this.request.setStatus(value);
        return this;
    }

    public BackOfficeRequestBuilder type(BackOfficeRequestType value) {
        this.request.setType(value);
        return this;
    }

    public BackOfficeRequestBuilder content(InputStream input) {
        this.request.setFormContent(input);
        return this;
    }

    public BackOfficeRequestBuilder formReferenceValue(Long id) {
        this.request.setFormReferenceValue(id);
        return this;
    }

    public BackOfficeRequestBuilder property(BackOfficeRequestProperty property, String value) {
        this.request.addRequestValue(property, value);
        return this;
    }

    public BackOfficeRequestBuilder property(BackOfficeRequestProperty property, BigDecimal value) {
        this.request.addRequestValue(property, value);
        return this;
    }

    public BackOfficeRequestBuilder property(BackOfficeRequestProperty property, Date value) {
        this.request.addRequestValue(property, value);
        return this;
    }

}
